<?php

namespace App\Http\Middleware;

use Closure,Session,Request,Redirect;

class OldMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //获得权限
        $action=Session::get('admin_power');
        if($action==''){
            $action=array('admin/checku','/admin/top','/admin/left','/admin/main','/admin/checku','/admin/index');
        }else{
            $action=array_merge($action,array('admin/checku','/admin/top','/admin/left','/admin/main','/admin/checku','/admin/index'));
        }
        $now_path=Request::getRequestUri();
        $now_path=substr($now_path, 15);
        if(strpos($now_path,'?')){
            $now_path=substr($now_path,0,strpos($now_path,'?'));
        }
        //判断权限
        if(!in_array($now_path,$action)){
            
            
            return redirect('/admin/login');
            
        }
        $now_path='/gitDemo/public'.$now_path;
        return $next($request);
    }
    public function terminate($request, $response)
    {
        // Store the session data...
    }
}
